package com.uenpay.im.ui.old.activity.attendance;

import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;
import com.uenpay.im.invokeitems.BaseHttpInvokeItem;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * @author SL
 * @created 2016-3-21 14:33:16
 * @copyRight http://www.qiyunxin.com
 * @function 获取签到时间
 */
public class GetSignInTimeInvokeItem extends BaseHttpInvokeItem {

	public class GetSignInTimeInvokeItemResult extends HttpInvokeResult {
		public String address;
		public String sign_in_time;
		public String sing_out_time;
		public String latitude, longitude;
	}

	public GetSignInTimeInvokeItemResult getOutPut() {
		return (GetSignInTimeInvokeItemResult) GetResultObject();
	}

	public GetSignInTimeInvokeItem(int entid) {
		String url = APIConfiguration.getBaseUrl()
				+ "Oa/Attendance/getTimeTable?entid=" + entid + "&"
				+ APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		GetSignInTimeInvokeItemResult result = new GetSignInTimeInvokeItemResult();
		try {
			JSONObject json = new JSONObject(responseBody);
			result.status = json.optInt("status");
			result.msg = json.optString("msg");
			if (json.has("data")) {
				JSONObject DataJson = json.optJSONObject("data");
				if (DataJson != null) {
					if (DataJson.has("address")) {
						result.address = DataJson.optString("address");
					}
					if (DataJson.has("starttime")) {
						result.sign_in_time = DataJson.optString("starttime");
					}
					if (DataJson.has("endtime")) {
						result.sing_out_time = DataJson.optString("endtime");
					}
					if (DataJson.has("latitude")) {
						result.latitude = DataJson.optString("latitude");
					}
					if (DataJson.has("longitude")) {
						result.longitude = DataJson.optString("longitude");
					}
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return result;
		}

		return result;
	}

}
